package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.YXDAPP;
import cn.acewill.yxd.yunxundian.model.RMain;
import cn.acewill.yxd.yunxundian.model.YxdEvaluationBean;
import cn.acewill.yxd.yunxundian.model.tempLostRR;

/**
 * Created by AAA on 2017/4/20.
 */

public class SlidAdapter extends BaseAdapter{

    protected YXDAPP yxdapp=new YXDAPP();
    protected DbManager db = x.getDb(yxdapp.getDaoConfig());
    private Context context;
    private  List<RMain.TablesBean.RowsBean.Q2Bean> mList;
    private deleteItem deleteItem;
    private  tempLostRR rr;

    public SlidAdapter(Context context,List<RMain.TablesBean.RowsBean.Q2Bean> list,deleteItem deleteItem){
        this.context=context;
        this.mList=list;
        this.deleteItem=deleteItem;
    }

    @Override
    public int getCount() {
        return mList==null?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=LayoutInflater.from(context).inflate(R.layout.yxd_evaluation,parent,false);
            holder=new ViewHolder();
            holder.EvaTitle= (TextView) convertView.findViewById(R.id.EvaTitle);
            holder.deleteEva= (TextView) convertView.findViewById(R.id.deleteEva);
            holder.reDesc= (TextView) convertView.findViewById(R.id.reDesc);
            holder.modifiEva= (TextView) convertView.findViewById(R.id.modifiEva);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        RMain.TablesBean.RowsBean.Q2Bean bean=mList.get(position);

        /*title*/
        holder.EvaTitle.setText(bean.getSName()+"\t"+bean.getReportRowName());
        /*超链接*/
        if(bean.getDescription()==null|| TextUtils.isEmpty(bean.getDescription())){
            holder.reDesc.setVisibility(View.GONE);
        }else{
            holder.reDesc.setText(bean.getDescription());
        }
        holder.deleteEva.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteItem.deleteClick(position);
            }
        });
        holder.modifiEva.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                deleteItem.modifiClick(position);
            }
        });
        return convertView;
    }
    class ViewHolder {
        TextView reDesc;
        TextView deleteEva;
        TextView EvaTitle;
        TextView modifiEva;
    }

    public interface deleteItem{
        void deleteClick(int position);
        void modifiClick(int position);
    }
}
